<!DOCTYPE html>
<html lang="zh-cn">
<head>
  <meta charset="utf-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
  <title>从virtualbox创建vagrant box - (power up)</title>
  <meta name="renderer" content="webkit" />
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1"/>

<meta http-equiv="Cache-Control" content="no-transform" />
<meta http-equiv="Cache-Control" content="no-siteapp" />

<meta name="theme-color" content="#f8f5ec" />
<meta name="msapplication-navbutton-color" content="#f8f5ec">
<meta name="apple-mobile-web-app-capable" content="yes">
<meta name="apple-mobile-web-app-status-bar-style" content="#f8f5ec">


<meta name="author" content="Kevin Jiang" /><meta name="description" content="有的时候vagrant官网提供的boxes可能并不是想要的，有些包含了太多东西，有些box又没有需要的。如果你的开发团队需要这样的一个box" /><meta name="keywords" content="KevinJiang, AI大模型, AI落地, 全栈工程师, Java, Spring Boot" />






<meta name="generator" content="Hugo 0.84.4 with theme even" />


<link rel="canonical" href="http://kevinjiang.info/post/%E4%BB%8Evirtualbox%E5%88%9B%E5%BB%BAvagrant-box/" />
<link rel="apple-touch-icon" sizes="180x180" href="/apple-touch-icon.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<link rel="mask-icon" href="/safari-pinned-tab.svg" color="#5bbad5">



<link href="/sass/main.min.78f8f17bab244b9ee62ad16480c9584d5fc2db06ae20681d1ca225cefd80767c.css" rel="stylesheet">
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.css" integrity="sha256-7TyXnr2YU040zfSP+rEcz29ggW4j56/ujTPwjMzyqFY=" crossorigin="anonymous">


<meta property="og:title" content="从virtualbox创建vagrant box" />
<meta property="og:description" content="有的时候vagrant官网提供的boxes可能并不是想要的，有些包含了太多东西，有些box又没有需要的。如果你的开发团队需要这样的一个box" />
<meta property="og:type" content="article" />
<meta property="og:url" content="http://kevinjiang.info/post/%E4%BB%8Evirtualbox%E5%88%9B%E5%BB%BAvagrant-box/" /><meta property="article:section" content="post" />
<meta property="article:published_time" content="2016-08-24T22:40:54+00:00" />
<meta property="article:modified_time" content="2016-08-24T22:40:54+00:00" />

<meta itemprop="name" content="从virtualbox创建vagrant box">
<meta itemprop="description" content="有的时候vagrant官网提供的boxes可能并不是想要的，有些包含了太多东西，有些box又没有需要的。如果你的开发团队需要这样的一个box"><meta itemprop="datePublished" content="2016-08-24T22:40:54+00:00" />
<meta itemprop="dateModified" content="2016-08-24T22:40:54+00:00" />
<meta itemprop="wordCount" content="899">
<meta itemprop="keywords" content="vagrant,virtualbox," /><meta name="twitter:card" content="summary"/>
<meta name="twitter:title" content="从virtualbox创建vagrant box"/>
<meta name="twitter:description" content="有的时候vagrant官网提供的boxes可能并不是想要的，有些包含了太多东西，有些box又没有需要的。如果你的开发团队需要这样的一个box"/>

<!--[if lte IE 9]>
  <script src="https://cdnjs.cloudflare.com/ajax/libs/classlist/1.1.20170427/classList.min.js"></script>
<![endif]-->

<!--[if lt IE 9]>
  <script src="https://cdn.jsdelivr.net/npm/html5shiv@3.7.3/dist/html5shiv.min.js"></script>
  <script src="https://cdn.jsdelivr.net/npm/respond.js@1.4.2/dest/respond.min.js"></script>
<![endif]-->

</head>
<body>
  <div id="mobile-navbar" class="mobile-navbar">
  <div class="mobile-header-logo">
    <a href="/" class="logo">(Power up)</a>
  </div>
  <div class="mobile-navbar-icon">
    <span></span>
    <span></span>
    <span></span>
  </div>
</div>
<nav id="mobile-menu" class="mobile-menu slideout-menu">
  <ul class="mobile-menu-list">
    <a href="/">
        <li class="mobile-menu-item">首页</li>
      </a><a href="/post/">
        <li class="mobile-menu-item">归档</li>
      </a><a href="/tags/">
        <li class="mobile-menu-item">标签</li>
      </a><a href="/categories/">
        <li class="mobile-menu-item">分类</li>
      </a><a href="/resume/">
        <li class="mobile-menu-item">简历</li>
      </a>
  </ul>

  


</nav>

  <div class="container" id="mobile-panel">
    <header id="header" class="header">
        <div class="logo-wrapper">
  <a href="/" class="logo">(Power up)</a>
</div>





<nav class="site-navbar">
  <ul id="menu" class="menu">
    <li class="menu-item">
        <a class="menu-item-link" href="/">首页</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/post/">归档</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/tags/">标签</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/categories/">分类</a>
      </li><li class="menu-item">
        <a class="menu-item-link" href="/resume/">简历</a>
      </li>
  </ul>
</nav>

    </header>

    <main id="main" class="main">
      <div class="content-wrapper">
        <div id="content" class="content">
          <article class="post">
    
    <header class="post-header">
      <h1 class="post-title">从virtualbox创建vagrant box</h1>

      <div class="post-meta">
        <span class="post-time"> 2016-08-24 </span>
        
          <span class="more-meta"> 约 899 字 </span>
          <span class="more-meta"> 预计阅读 2 分钟 </span>
        
      </div>
    </header>

    <div class="post-toc" id="post-toc">
  <h2 class="post-toc-title">文章目录</h2>
  <div class="post-toc-content always-active">
    <nav id="TableOfContents"></nav>
  </div>
</div>
    <div class="post-content">
      <p>有的时候vagrant官网提供的boxes可能并不是想要的，有些包含了太多东西，有些box又没有需要的。如果你的开发团队需要这样的一个box，那么你就应该自己动手创建一个。其实创建的过程挺简单的，只要每个步骤操作正确。</p>
<p>Follow下面步骤：</p>
<p>1、安装vagrant</p>
<p>2、安装virtualbox</p>
<p>3、在virtualbox创建一个linux (centos)，假设名字叫centos</p>
<p>4、创建好centos后，还需要安装virtualbox的guest增强插件。安装之前需要在centos安装一些必须的工具：</p>
<pre><code># yum install kernel-devel gcc perl
# ln -s /usr/src/kernels/2.6.18-164.15.1.el5-i686 /usr/src/linux 
</code></pre>
<p>上面第二行请把版本号换成你自己安装的centos的内核版本号，你可以通过<code>uname -a</code>查看，或者直接到<code>/user/src/kernels</code>目录查看即可</p>
<p>5、还需要创建一个<code>vagrant</code>账号，密码也是vagrant。注意请把<code>root</code>密码也设置成<code>vagrant</code></p>
<pre><code># groupadd vagrant
# useradd -g vagrant vagrant
# passwd vagrant
</code></pre>
<p>另外还需要设置sudo，因为vagrant默认会使用vagrant账号挂载工作目录到<code>/vagrant</code>。还需要设置<code>tty</code>，用root账号输入<code>visudo</code>，修改centos里面的<code>/etc/sudoers</code>注释下面两行</p>
<pre><code>#Defaults    requiretty
#Defaults   !visiblepw
</code></pre>
<p>添加下面一行到<code>root    ALL=(ALL)       ALL</code>下面</p>
<pre><code>vagrant ALL=(ALL)       ALL
</code></pre>
<p>6、检查<code>guest******.iso</code>是否加载，如果没有加载的话，请添加一个光驱，并且加载这个iso文件，一般这个iso文件在virtualbox的安装目录可以找到</p>
<p>7、连接上终端，输入下面的命令：</p>
<pre><code>mount /dev/cdrom /media/cdrom
cd /media/cdrom
./VBoxLinuxAdditions.run
</code></pre>
<p>如果没有error说明安装成功，如果有关于X的错误，有可能是你没有安装X环境，如果只是使用命令行，这个也不用管</p>
<p>8、打包</p>
<pre><code>vagrant package --base centos --output centos.box
</code></pre>
<p><code>vagrant package</code>就是vagrant用来打包的命令，<code>--base</code>指定你创建的虚拟机的名字，后面<code>--output</code>指定导出的box的位置和名字</p>
<p>9、打好包后，自己可以建立一个新的环境测试一下：</p>
<pre><code>vagrant box add base centos.box
cd your vagrant workspace dir
vagrant init base
</code></pre>
<p>10、这里要注意的一点是，由于没有找到使用publickey登录的方式，所以必须要在<code>Vagrantfile</code>的最后添加用户名和密码登录</p>
<pre><code>Vagrant.configure(&quot;2&quot;) do |config|
  # 添加下面两行使用用户名密码登录
  config.ssh.username = &quot;root&quot;
  config.ssh.password = &quot;vagrant&quot;
end
</code></pre>
<p>11、启动</p>
<pre><code>vagrant up
</code></pre>

    </div>

    <div class="post-copyright">
  <p class="copyright-item">
    <span class="item-title">文章作者</span>
    <span class="item-content">Kevin Jiang</span>
  </p>
  <p class="copyright-item">
    <span class="item-title">上次更新</span>
    <span class="item-content">
        2016-08-24
        
    </span>
  </p>
  
  <p class="copyright-item">
    <span class="item-title">许可协议</span>
    <span class="item-content"><a rel="license noopener" href="https://creativecommons.org/licenses/by-nc-nd/4.0/" target="_blank">CC BY-NC-ND 4.0</a></span>
  </p>
</div>
<div class="post-reward">
  <input type="checkbox" name="reward" id="reward" hidden />
  <label class="reward-button" for="reward">赞赏支持</label>
  <div class="qr-code">
    
    <label class="qr-code-image" for="reward">
        <img class="image" src="/img/wechat_pay_1242x1242.jpg">
        <span>微信打赏</span>
      </label>
    <label class="qr-code-image" for="reward">
        <img class="image" src="/img/alipay_600x600.jpg">
        <span>支付宝打赏</span>
      </label>
  </div>
</div><footer class="post-footer">
      <div class="post-tags">
          <a href="/tags/vagrant/">vagrant</a>
          <a href="/tags/virtualbox/">virtualbox</a>
          </div>
      <nav class="post-nav">
        <a class="prev" href="/post/emacs/spacemacs%E9%85%8D%E7%BD%AEfigwheel%E7%8E%AF%E5%A2%83/">
            <i class="iconfont icon-left"></i>
            <span class="prev-text nav-default">spacemacs配置figwheel环境</span>
            <span class="prev-text nav-mobile">上一篇</span>
          </a>
        <a class="next" href="/post/java/scala%E5%AD%A6%E4%B9%A0%E7%AC%94%E8%AE%B0%E4%B9%8B%E6%AD%A3%E5%88%99%E8%A1%A8%E8%BE%BE%E5%BC%8F/">
            <span class="next-text nav-default">Scala学习笔记之正则表达式</span>
            <span class="next-text nav-mobile">下一篇</span>
            <i class="iconfont icon-right"></i>
          </a>
      </nav>
    </footer>
  </article>
        </div>
        

  

  

      </div>
    </main>

    <footer id="footer" class="footer">
      <div class="social-links">
      <a href="mailto:wenlin1988@126.com" class="iconfont icon-email" title="email"></a>
      <a href="https://www.linkedin.com/in/%E6%96%87%E6%9E%97-%E8%92%8B-0a3204126/" class="iconfont icon-linkedin" title="linkedin"></a>
      <a href="https://github.com/kevindragon" class="iconfont icon-github" title="github"></a>
  <a href="http://kevinjiang.info/index.xml" type="application/rss+xml" class="iconfont icon-rss" title="rss"></a>
</div>

<div class="copyright">
  <span class="power-by">
    由 <a class="hexo-link" href="https://gohugo.io">Hugo</a> 强力驱动
  </span>
  <span class="division">|</span>
  <span class="theme-info">
    主题 -
    <a class="theme-link" href="https://github.com/olOwOlo/hugo-theme-even">Even</a>
  </span>

  

  <span class="copyright-year">
    &copy;
    2015 -
    2023<span class="heart"><i class="iconfont icon-heart"></i></span><span>Kevin Jiang</span>
    <a href="https://beian.miit.gov.cn/" target="_blank">湘ICP备2022022745号</a>
  </span>
</div>

    </footer>

    <div class="back-to-top" id="back-to-top">
      <i class="iconfont icon-up"></i>
    </div>
  </div>
  
  <script src="https://cdn.jsdelivr.net/npm/jquery@3.2.1/dist/jquery.min.js" integrity="sha256-hwg4gsxgFZhOsEEamdOYGBf13FyQuiTwlAQgxVSNgt4=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/slideout@1.0.1/dist/slideout.min.js" integrity="sha256-t+zJ/g8/KXIJMjSVQdnibt4dlaDxc9zXr/9oNPeWqdg=" crossorigin="anonymous"></script>
  <script src="https://cdn.jsdelivr.net/npm/@fancyapps/fancybox@3.1.20/dist/jquery.fancybox.min.js" integrity="sha256-XVLffZaxoWfGUEbdzuLi7pwaUJv1cecsQJQqGLe7axY=" crossorigin="anonymous"></script>



<script type="text/javascript" src="/js/main.min.c99b103c33d1539acf3025e1913697534542c4a5aa5af0ccc20475ed2863603b.js"></script>
  <script type="text/javascript">
    window.MathJax = {
      tex: {
        inlineMath: [['$','$'], ['\\(','\\)']],
        tags: 'ams',
        }
    };
  </script>
  <script type="text/javascript" async src="/lib/mathjax/es5/tex-mml-chtml.js"></script>

<script id="baidu_analytics">
  var _hmt = _hmt || [];
  (function() {
    if (window.location.hostname === 'localhost') return;
    var hm = document.createElement("script"); hm.async = true;
    hm.src = "https://hm.baidu.com/hm.js?b73ff6d4afc4af9e582d8a5dc068bab9";
    var s = document.getElementsByTagName("script")[0];
    s.parentNode.insertBefore(hm, s);
  })();
</script>






</body>
</html>
